<?php
// 开启调试
define('WP_DEBUG', true);

// 关闭管理工具栏
show_admin_bar(false);


function themeslug_enqueue_style()
{

    // 如果是子主题，则先加载父主题样式
    if (is_child_theme()) {
        wp_enqueue_style('parent-stylesheet', trailingslashit(get_template_directory_uri()) . 'style.css');
        wp_enqueue_style('parent-flat-ui-stylesheet', trailingslashit(get_template_directory_uri()) . 'css/flat-ui.css');
    }
    // 加载主题默认样式
    wp_enqueue_style('theme-stylesheet', get_stylesheet_uri());

    // 加载主题样式
    wp_enqueue_style('bootstrap-css', "https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css");
    // 加载主题脚本
    wp_enqueue_script('jquery', 'https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js');
    wp_enqueue_script('popper', 'https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js');
    wp_enqueue_script('bootstrap-js', 'https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js');
}

add_action('wp_enqueue_scripts', 'themeslug_enqueue_style');

// 注册自定义菜单
register_nav_menus(
	array(
		'header-menu' => __('头部导航菜单'),
		'main-menu' => __('导航菜单'),
		'footer-menu' => __('底部航菜单')
	)
);

// 自定义菜单处理类
class wp_bootstrap_navwalker extends Walker_Nav_Menu
{

    public function start_lvl(&$output, $depth = 0, $args = array())
    {
        if ($args->walker->has_children) {
            $output = $output . '<ul class="dropdown-menu">';
        } else {
            $output = $output . '<ul class="nav navbar-nav">';
        }
    }

    public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
    {
        $id = apply_filters('nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args, $depth);
        $id = $id ? ' id="' . esc_attr($id) . '"' : '';
        if ($args->walker->has_children&&$depth==0) {
            $myoutput = "\n<li {$id} class='dropdown'>";
            $myoutput = $myoutput . '<a href="'.$item->url.'" class="dropdown-toggle" data-toggle="dropdown">' . $item->title . '</a>';
        } else {
            $myoutput = "\n<li>";
            $myoutput = $myoutput . '<a href='.$item->url.'>' . $item->title . '</a>';
        }
        $output = $output . $myoutput;
        return;
    }

    public function end_el(&$output, $item, $depth = 0, $args = array())
    {
        $myoutput = "";
        if ($args->walker->has_children) {
            $myoutput = '</li>';
        } else {
            $myoutput = $myoutput . '</li>';
        }
        $output = $output . $myoutput;
        return;
    }
}
//===========================================================================================================
?>